package com.hdax.dm.feign.fallback;

import com.hdax.dm.entity.base.Image;
import com.hdax.dm.feign.ImageFeign;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class ImageFallbackFactory implements FallbackFactory<ImageFeign> {


    //当远程调用失败的时候，下面方法会执行
    @Override
    public ImageFeign create(Throwable cause) {
        return new ImageFeign() {
            //内部接口实现
            @Override
            public Image image(Long targetId, Long type, Long category) {

                Image image=new Image();
                image.setImgUrl("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202006%2F28%2F20200628115437_MJ4tP.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1669174639&t=ca6a7e1e6517c9f76a2dea334ab6d69c");
                System.out.println("==============================");
                System.err.println("远程调用失败");
                System.out.println("==============================");
                return image;
            }
        };
    }
}
